#!/usr/bin/python

import fm
import wx
import wx.stc as stc

from fm import if_Mac_Unix_Win

settings=fm.settings


# ?? s / text. / text_style. as in text_style.string.fg_color
# ?? s / text. / style.text. as in style.text.string.foreground
# ?? s / text. / textstyle. as in textstyle.string.colorfg
# ?? s / color_fg / fg
# ?? s / color_fg / fg_color? no need, if for filtering, can filter based on actual type
# ?? s / color_fg / foreground?
# ?? s / color_fg / foreground_color?
# ?? s / color_fg / colorfg ***
def inherit_all_text_attributes(dst,src):
	for __ in ('font','color_fg','color_bg','italic','underline','bold'):
		settings[dst+__]=settings[src+__]

settings['text.default.font']=if_Mac_Unix_Win('Monaco','Courier New','Courier')
settings['text.default.size']=if_Mac_Unix_Win(14,10,12)
settings['text.default.color_fg']=wx.BLACK
settings['text.default.color_bg']=wx.ColourRGB(0xDDDDDD)
settings['text.margin.colorbg']=wx.ColourRGB(0xC0C0C0)

settings['text.__inherited__.size']=if_Mac_Unix_Win(14,10,12)

for s in ('italic','underline','bold'): settings['text.default.'+s]=False

inherit_all_text_attributes('text.string.','text.default.')
inherit_all_text_attributes('text.comment.','text.default.')
inherit_all_text_attributes('text.keyword.','text.default.')
inherit_all_text_attributes('text.methodname.','text.default.')
inherit_all_text_attributes('text.classname.','text.default.')
inherit_all_text_attributes('text.delimeter.','text.default.')
inherit_all_text_attributes('text.char.','text.default.')
inherit_all_text_attributes('text.number.','text.default.')

settings['text.string.color_fg']    = wx.ColourRGB(0xff0000)

settings['text.comment.color_fg']   = wx.ColourRGB(0x555555)

settings['text.keyword.color_fg']   = wx.ColourRGB(0x00007F)
settings['text.keyword.bold']   = True

settings['text.methodname.color_fg']    = wx.ColourRGB(0x555555)
settings['text.classname.color_fg']     = wx.ColourRGB(0x555555)
settings['text.delimeter.color_fg'] = wx.ColourRGB(0x555555)
settings['text.char.color_fg']      = wx.ColourRGB(0x555555)
settings['text.number.color_fg']    = wx.ColourRGB(0x555555)

"""

def configure_stc_styles(tx):
	# adopted from the wxPython example
	tx.SetLexer(stc.STC_LEX_PYTHON)
	tx.SetKeyWords(0, settings['mode.keywords'])
	
	tx.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d,back:#DDDDDD" % settings['text.faces'])

	tx.StyleClearAll()
	
	# Global default styles for all languages
	tx.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d,back:#DDDDDDt" % settings['text.faces'])
	tx.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % settings['text.faces'])
	tx.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % settings['text.faces'])
	tx.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
	tx.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")

	# Python styles
	# Default 
	tx.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Comments
	tx.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#555555,face:%(other)s,size:%(size)d" % settings['text.faces'])
	# Number
	#tx.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % settings['text.faces'])
	# String
	tx.StyleSetSpec(stc.STC_P_STRING, "fore:#FF0000,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Single quoted string
	tx.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#FF0000,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Keyword
	tx.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % settings['text.faces'])
	# Triple quotes
	tx.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#FF0000,size:%(size)d" % settings['text.faces'])
	# Triple double quotes
	tx.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#FF0000,size:%(size)d" % settings['text.faces'])
	# Class name definition
	tx.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % settings['text.faces'])
	# Function or method name definition
	tx.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#0000FF,bold,size:%(size)d" % settings['text.faces'])
	# Operators
	tx.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % settings['text.faces'])
	# Identifiers
	tx.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Comment-blocks
	tx.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % settings['text.faces'])
	# End of line where string is not closed
	tx.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % settings['text.faces'])

	tx.SetCaretForeground(settings['text.caret_foreground'])
"""
